package com.example.finalassignment.mapper;

import com.example.finalassignment.pojo.Life;
import com.example.finalassignment.pojo.Stars;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* @author guocheng
* @description 针对表【life(分享生活日常或者有趣的事表)】的数据库操作Mapper
* @createDate 2024-06-10 16:54:53
* @Entity com.example.finalassignment.pojo.Life
*/
public interface LifeMapper {

    int deleteByPrimaryKey(Long id);

    int insert(Life record);

    int insertSelective(Life record);

    Life selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Life record);

    int updateByPrimaryKey(Life record);

    @Select("select * from life where status != 0 order by create_time desc")
    List<Map<String,Object>> getListToVideo();

    /**
     * 加1
     * @param id
     * @return
     */
    @Update("update life set star = star + 1 where id = #{id}")
    int updateDraftsByUUIDToStarsAdd(@Param("id")String id);

    /**
     * 减1
     * @param id
     * @return
     */
    @Update("update life set star = GREATEST(star - 1, 0) where id = #{id}")
    int updateDraftsByUUIDToStarsCut(@Param("id")String id);

    /**
     * 模糊查询
     */
    @Select("select * from life where status != 0 and (title like concat('%',#{value},'%') or description like concat('%',#{value},'%'))")
    List<Map<String,Object>> getAllDataByLike(@Param("value") String value);
}
